// Transform Callback-style function to Promise-style function.
export type AwCallback<RES> = (res?: RES) => void;
export function aw(num: number): Promise<void>;
export function aw<A, B, C, D, E, /**/ RES>(exec: (a: A, b: B, c: C, d: D, e: E, callback: AwCallback<RES>) => void, a: A, b: B, c: C, d: D, e: E): Promise<RES>;
export function aw<A, B, C, D, /*---*/ RES>(exec: (a: A, b: B, c: C, d: D, /*-*/ callback: AwCallback<RES>) => void, a: A, b: B, c: C, d: D /*-*/): Promise<RES>;
export function aw<A, B, C, /*------*/ RES>(exec: (a: A, b: B, c: C, /*-------*/ callback: AwCallback<RES>) => void, a: A, b: B, c: C /*-------*/): Promise<RES>;
export function aw<A, B, /*---------*/ RES>(exec: (a: A, b: B, /*-------------*/ callback: AwCallback<RES>) => void, a: A, b: B /*-------------*/): Promise<RES>;
export function aw<A, /*------------*/ RES>(exec: (a: A, /*-------------------*/ callback: AwCallback<RES>) => void, a: A /*-------------------*/): Promise<RES>;
export function aw</*---------------*/ RES>(exec: (/*-------------------------*/ callback: AwCallback<RES>) => void /*-------------------------*/): Promise<RES>;
export async function aw(execOrNum: number | ((...res: any[]) => void), ...args: any[]) {
  const exec = typeof execOrNum !== "number" ? execOrNum : (r: any) => setTimeout(r, execOrNum);
  const res = await new Promise(r => exec.apply(null, [...args, r]));
  if (res instanceof Error) throw res;
  /*---------------*/ else return res;
}
